package com.example.LibrarySystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.LibrarySystem.mapper.BookClassesMapper;
import com.example.LibrarySystem.pojo.BookClasses;
import com.example.LibrarySystem.pojo.User;
import com.example.LibrarySystem.service.BookClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class BookClassesServiceImpl implements BookClassesService {
    @Autowired
    private BookClassesMapper bookClassesMapper;

    @Override
    public IPage<BookClasses> getBookClassesByAll(Map<String, String> data) {
        int start = data.containsKey("start") ? Integer.parseInt(data.get("start")) : 1;
        int pages = data.containsKey("pages") ? Integer.parseInt(data.get("pages")) : 10;

        IPage<BookClasses> userIPage = new Page<>(start, pages);

        QueryWrapper<BookClasses> queryWrapper = new QueryWrapper<>();

        if (data.containsKey("name") && !"".equals(data.get("name"))) {
            queryWrapper.like("name", data.get("name"));
        }
        return bookClassesMapper.selectPage(userIPage, queryWrapper);
    }
}
